using AutoMapper;
using Blog.Repository;
using Blog.Repository.View;
using Blog.Service.View.Output;
using XjjXmm.Infrastructure.Repository;
using XjjXmm.Infrastructure.User;

namespace Blog.Service.View;



/// <summary>
/// 视图管理
///</summary>
public class ViewService : CrudService<ViewModel, ViewEntity>, IViewService
{
    private readonly IViewRepository _viewRepository;

    public ViewService(IViewRepository viewRepository, IUser user, IMapper mapper) : base(viewRepository, user, mapper)
    {
        _viewRepository = viewRepository;
    }

    public async Task<List<ViewListOutput>> List(string? key)
    {
        //var data = await _viewRepository
        //    .WhereIf(key.NotNull(), a => a.Path.Contains(key) || a.Label.Contains(key))
        //    .OrderBy(a => a.ParentId)
        //    .OrderBy(a => a.Sort)
        //    .ToListAsync<ViewListOutput>();

        var data = await _viewRepository.GetAll();

        return _mapper.Map<List<ViewListOutput>>(data);

        //throw new NotImplementedException();
    }
}